﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CanvasEx.DrawCore;
using System.Runtime.InteropServices;


namespace CanvasEx
{
    public class CanvasEx : Canvas
    {
        List<Painter> painterlist = new List<Painter>();
        Painter ActionPainter;

        public static DependencyProperty CoordinatePositionProperty;
        static CanvasEx()
        {
            CoordinatePositionProperty =
                DependencyProperty.Register("CoordinatePosition", typeof(string), typeof(CanvasEx), new PropertyMetadata());
        }
        public string CoordinatePosition
        {
            get { return (string)GetValue(CoordinatePositionProperty); }
            set { SetValue(CoordinatePositionProperty, value); }
        }
        

        public CanvasEx()
        {
            this.Focusable = true;//重要：默认条件下不接收鼠标事件
            this.Background = new SolidColorBrush(Colors.Black);
            this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            this.MouseMove += new MouseEventHandler(CanvasEx_MouseMove);           
        }
        internal void AddPainter(Painter p)
        {
            painterlist.Add(p);
            ActionPainter = p;
        }
        public void SetAction(int index)
        {
            ActionPainter = painterlist[index];
        }

        private void CanvasEx_MouseMove(object sender, MouseEventArgs e)
        {
            Point Location = e.GetPosition(this);
            Location.Y = this.ActualHeight - Location.Y;
            CoordinatePosition = Location.X + " , " + Location.Y;
        }
    }



}
